/*
 * @version: 1.0
 * @Author: zhl
 * @Date: 2021-09-16 09:58:02
 * @LastEditors: zhl
 * @LastEditTime: 2022-01-14 14:44:53
 * @Description: 文件实现描述
 */

#ifndef __TASK_THREAD_MANAGER_H__
#define __TASK_THREAD_MANAGER_H__

#include <unordered_map>
#include <list>
#include <pthread.h>
#include <memory>

#include "CConfigManager.h"
#include "CModuleManager.h"
#include "HandleThreadManager.h"
#include "global_data_struct.h"




class TaskThreadManager{
    private:
        pthread_t c_thread;
        uint32_t  c_intervaltime;
        std::unordered_map<std::string, std::shared_ptr<HandleThreadManager>> c_htms;

        uint32_t  get_intervaltime(int64_t item_id, bool is_first = false);

    public:
        bool c_is_run;
        std::shared_ptr<CConfigManager> c_cm;
        std::shared_ptr<std::unordered_map<int64_t, TASK_PARAMS>> c_task_params;

    public:
        TaskThreadManager(std::shared_ptr<CConfigManager> cm, std::unordered_map<std::string, std::shared_ptr<HandleThreadManager>> &htm);
        ~TaskThreadManager();

        static void *handle_thread(void *arg);
        int execute(std::unordered_map<int64_t, TASK_PARAMS> &devs);
        int wait_thread_finish();
        void stop();
};






#endif/* __TASK_THREAD_MANAGER_H__ */
